package com.wanmait.happyheating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.happyheating.mapper.ComplainsMapper;
import com.wanmait.happyheating.mapper.ConfigMapper;
import com.wanmait.happyheating.pojo.ComplainsType;
import com.wanmait.happyheating.mapper.ComplainsTypeMapper;
import com.wanmait.happyheating.pojo.Config;
import com.wanmait.happyheating.pojo.FaultType;
import com.wanmait.happyheating.service.ComplainsTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.happyheating.service.ConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 投诉类型表 服务实现类
 * </p>
 *
 * @author yuQianTao
 * @since 2021-05-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ComplainsTypeServiceImpl extends ServiceImpl<ComplainsTypeMapper, ComplainsType> implements ComplainsTypeService {
    @Resource
    private ComplainsTypeMapper complainsTypeMapper;

    @Resource
    private ConfigMapper configMapper;

    @Override
    public PageInfo<ComplainsType> fuzzyPagingQuery(Integer pageNum, Integer pageSize, String title) {
        Integer navigatePages = this.getNavigatePages();
        //暂时每页显示条数为3 后期通过数据库读取
        LambdaQueryWrapper<ComplainsType> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(ComplainsType::getTitle,title);
        PageHelper.startPage(pageNum,pageSize);
        List<ComplainsType> List=complainsTypeMapper.selectList(queryWrapper);
        //暂时导航页码数为5
        PageInfo<ComplainsType> pageInfo=new PageInfo<>(List,navigatePages);
        return pageInfo;
    }

    @Override
    public PageInfo<ComplainsType> findByPage(Integer pageNum, Integer pageSize) {

        //暂时每页显示条数为3 后期通过数据库读取
        PageHelper.startPage(pageNum,pageSize);
        List<ComplainsType> List=complainsTypeMapper.selectList(null);
        //暂时导航页码数为5
        PageInfo<ComplainsType> pageInfo=new PageInfo<>(List,5);
        return pageInfo;


    }

    /**
     * 获取配置表中的每页最大显示数量
      * @return 每页最大显示数量
     */
    private Integer getPageSize(){
        LambdaQueryWrapper<Config> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Config::getTitle,"分页最大显示数据");
        Config config =  configMapper.selectOne(queryWrapper);
        return Integer.parseInt(config.getValue());

    }
    /**
     * 获取配置表中的导航页码数
     * @return 导航页码数
     */
    private Integer getNavigatePages(){
        LambdaQueryWrapper<Config> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Config::getTitle,"导航页码数");
        Config config =  configMapper.selectOne(queryWrapper);
        return Integer.parseInt(config.getValue());

    }


}
